"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenLinkCommand = void 0;
const open_1 = __importDefault(require("open"));
const chalk_1 = __importDefault(require("chalk"));
const inquirer_1 = __importDefault(require("inquirer"));
const error_1 = require("../../error");
const common_1 = require("../common");
const decorators_1 = require("../../decorators");
const links = [
    {
        name: 'CLI 文档',
        value: 'cli-doc',
        url: 'https://tencentcloudbase.github.io/2019-09-03-cli/'
    }
];
let OpenLinkCommand = class OpenLinkCommand extends common_1.Command {
    get options() {
        return {
            cmd: 'open [link]',
            options: [],
            desc: '在浏览器中打开云开发相关连接',
            requiredEnvId: false,
            withoutAuth: true
        };
    }
    execute(params) {
        return __awaiter(this, void 0, void 0, function* () {
            let openLink = null;
            const link = params === null || params === void 0 ? void 0 : params[0];
            if (link) {
                openLink = links.find((item) => item.value === link);
                if (!openLink) {
                    throw new error_1.CloudBaseError(`${link} 链接不存在！`);
                }
            }
            else {
                const { selectLink } = yield inquirer_1.default.prompt({
                    type: 'list',
                    name: 'selectLink',
                    message: '请选择需要打开的链接',
                    choices: links
                });
                openLink = links.find((item) => item.value === selectLink);
            }
            if (!openLink) {
                throw new error_1.CloudBaseError('请指定需要打开的链接！');
            }
            console.log(`在您的默认浏览器中打开 ${openLink.name} 链接：`);
            console.log(chalk_1.default.underline.bold(openLink.url));
            open_1.default(openLink.url);
        });
    }
};
__decorate([
    decorators_1.InjectParams(),
    __param(0, decorators_1.ArgsParams()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], OpenLinkCommand.prototype, "execute", null);
OpenLinkCommand = __decorate([
    common_1.ICommand()
], OpenLinkCommand);
exports.OpenLinkCommand = OpenLinkCommand;
